<template>
	<view>
		<view class="head">
			<view>当前余额</view>
			<view>{{banlance}}</view>

			<view class="bottom-right" @click="checkDetail">查看明细></view>
		</view>

		<view class="tail"> <u-button type="primary" style="border-radius: 10px;"
				@click="campusCardShow = true">充值</u-button>
		</view>

		<view>
			<u-popup :show="campusCardShow" mode="center" @close="close" @open="open">
				<view style="width: 300px;height: 200px;" class="uppo">
					<view>
						<view style="padding-left: 35px;padding-top: 20px;">充值缴费</view>
						<view style="display: flex;padding-left: 3px;padding-top: 17px;"> <u-input placeholder="请输入缴纳金额"
								border="surround" v-model="campusCardFee"></u-input></view>

					</view>
					<view style="margin-top: 40px;"> <u-button text="确认" @click="insertCampusCardFeeFun()"></u-button>
					</view>
				</view>
			</u-popup>
		</view>
	</view>
</template>

<script>
	import rechargeInfo from "@/api/campus/index.js"

	export default {
		data() {
			return {
				banlance: "",
				campusCardShow: false,
				campusCardFee: ""
			}
		},
		methods: {
			//跳转费用明细
			async checkDetail() {
				uni.navigateTo({
					url: '/pages/card/balance', // 跳转的目标页面路径
				});
			},
			async getBalance() {
				let response = await rechargeInfo.getBalence();

				if (response.data === "未查询到该学生校园卡信息") {
					this.banlance = null
				} else {
					this.banlance = response.data
				}
			},
			async insertCampusCardFeeFun() {
				try {
					let response = await rechargeInfo.insertCampusCard(this.campusCardFee);

					this.campusCardShow = false;
					this.getBalance()
					alert("充值成功")
				} catch (error) {
					console.log(error)
				}
			},
			close() {
				this.campusCardShow = false
			}

		},
		mounted() {
			this.getBalance()
		}
	}
</script>

<style>
	.tail {
		border-radius: 5px;
		margin: 15px;
		margin-top: 150px;
		height: 60px;
		/* 两端对齐，元素分布在两侧 */
	}

	.head {
		margin: 15px;
		margin-top: 30px;
		height: 70px;
		color: #1890ff;
		background-color: #f5f5f5;
		/* 非常浅灰色 */
		/* 浅蓝色 */
		border-radius: 5px;

		display: flex;
		/* 使用 Flexbox 布局 */
		justify-content: space-between;
		/* 子元素在两边对齐 */
		/* align-items: center; */
		/* 垂直居中 */
		padding: 10px;
		/* 父容器的内边距 */
		position: relative;
		/* 设置相对定位，为绝对定位子元素做准备 */
	}

	.bottom-right {
		position: absolute;
		/* 绝对定位 */
		bottom: 17px;
		/* 距离底部 10px */
		right: 10px;
		/* 距离右侧 10px */
		color: #000;
	}
</style>